<?php
namespace app\controller\admin\system\app;


use app\BaseController;
use app\common\repositories\system\SystemConfigValueRepository;
use basic\services\WechatService;
use Exception;
use think\db\exception\DbException;

class WechatMenu extends BaseController
{
    public function info()
    {
        return app('json')->success(systemConfig('app_wechat_menus')?:[]);
    }

    public function save()
    {
        $buttons = (array)$this->request->param('button', []);
        if (!count($buttons)) return app('json')->fail('请添加至少一个按钮');

        try {
            WechatService::create()->getService()->menu->create($buttons);
        } catch (Exception $e) {
            return app('json')->fail('设置失败:' . $e->getMessage());
        }

        app()->make(SystemConfigValueRepository::class)->setFormData(['app_wechat_menus'=>$buttons],0);
        return app('json')->success('设置成功');
    }
}